<template>
  <el-dialog :title="title" :visible.sync="dialogFormVisible" width="500px">
    <el-divider></el-divider>
    <el-form style="margin: 30px 150px 30px 50px;">
      <el-form-item label>
        <el-input v-model="row.name" placeholder="请输入类型名称"></el-input>
      </el-form-item>
    </el-form>
    <el-divider></el-divider>
    <div slot="footer" class="dialog-footer">
      <el-button @click="dialogFormVisible = false">取 消</el-button>
      <el-button type="primary" @click="update">确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
  export default{
    data(){
      return{
        dialogFormVisible:false,
        title:"编辑",
        row:[],
        idx:1
      }
    },
    mounted() {},
    methods:{
      getTitle(){
        if(this.idx == 0){  //idx等于0就是编辑
          this.title = "编辑";
        }else if(this.idx == 1){
          this.title = "添加";   //idx等于1就是添加
        }
      },
      update(row){
        var row = this.row;
        //编辑
        if(this.idx == 0){
          // 请求数据
          this.$axios.request({
            url:this.API+"/activity/activityType/update",
            data: row,
            method:"POST"
          }).then((res)=>{
            // console.log(res);
            if (res.data.code == 0) {  //编辑成功
              this.dialogFormVisible = false; //关闭窗口
              this.$message.success("编辑成功");
            }else{  //编辑失败
              this.$message.error(res.data.msg)
            }
          })
          //添加
        }else if(this.idx == 1){
          this.$axios.request({
            url:this.API + "/activity/activityType/save",
            data: {name: row.name},
            method: "post"
          }).then((res)=>{
            if(res.data.code == 0){  //添加成功
              this.parent.getData();
              this.dialogFormVisible = false;  //关闭窗口
              this.$message.success("添加成功");
            }else{  //添加失败
              this.$message.error(res.data.msg);
            }
          })
        }

      }
    },
    props:['parent']
  }
</script>

<style>
</style>

